<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>7. 实现trim(str)方法，过滤字符串首位空白</title>
</head>
<body>
    <script>
        String.prototype.firstTrim = function(){
            let look = false; // 条件锁
            let new_str = ""; // 返回值
            for(let i = 0;i<this.length;i++){
                if(str[i] != " "){
                    new_str += this[i];
                    look = true; 
                    // 头部空格去除后,把锁打开。后面的字符不再去空
                } else if(look){
                    new_str += this[i];
                }
            }
            return new_str;
        }
        let str = " 123 45645  64  ";
        let new_str = str.firstTrim();
        console.log(new_str);
        
    </script>
</body>
</html>